package com.video.main_video.manager.handle.collections;

import cn.hutool.core.bean.BeanUtil;

import com.video.main_video.api.Api;
import com.video.main_video.common.staticData.StaticData;
import com.video.main_video.dao.entity.Collections;
import com.video.main_video.dao.request.collection.CollectionAddRequest;
import com.video.main_video.dao.response.collection.CollectionsAddResponse;
import com.video.main_video.manager.handle.ApiHandler;
import com.video.main_video.manager.mapper.CollectionsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Api
public class CollectionsAddManager implements ApiHandler<CollectionAddRequest, CollectionsAddResponse> {

    @Autowired
    CollectionsMapper collectionsMapper;
    @Transactional
    @Override
    public CollectionsAddResponse handler(CollectionAddRequest collectionAddRequest) {

        createCollectFolder(collectionAddRequest);
        CollectionsAddResponse res=new CollectionsAddResponse();
        res.setMsg("创建成功");
        return res;
    }


    private void createCollectFolder(CollectionAddRequest req){
        Collections collections=new Collections();
        BeanUtil.copyProperties(req,collections);
        collections.setUserId(StaticData.UserId);
        collectionsMapper.insert(collections);
    }
}
